<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入昵称" v-model="queryParam.nickname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="手机号码">
              <a-input placeholder="请输入手机号码" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="会员状态">
              <a-select v-model="queryParam.status" placeholder="全部" @change="searchQuery">
                <a-select-option :value="1">
                  申请中
                </a-select-option>
                <a-select-option :value="2">
                  申请通过
                </a-select-option>
                <a-select-option :value="3">
                  申请拒绝
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
               :dataSource="dataSource" :pagination="ipagination"
               :loading="loading" class="j-table-force-wrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <template slot="statusSlot" slot-scope="text">
          <a-tag color="orange" v-if="text==1">
            申请中
          </a-tag>
          <a-tag color="green" v-if="text==2">
            申请通过
          </a-tag>
          <a-tag color="red" v-if="text==3">
            申请拒绝
          </a-tag>
        </template>


        <span slot="action" slot-scope="text, record">
          <a-popconfirm v-if="record.status==1" title="确定通过吗?" @confirm="() => handleEditPass(record)">
            <a>通过</a>
          </a-popconfirm>
          <a-divider v-if="record.status==1" type="vertical"/>
          <a-popconfirm v-if="record.status==1" title="确定拒绝吗?" @confirm="() => handleEditRefuse(record)">
            <a>拒绝</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <hms-hand-form-modal ref="modalForm" @ok="modalFormOk"></hms-hand-form-modal>
  </a-card>
</template>

<script>
import {putAction} from '@/api/manage'
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import HmsHandFormModal from './modules/HmsHandFormModal'

export default {
  name: 'HmsHandFormList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    HmsHandFormModal
  },
  data() {
    return {
      description: '分销员申请管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '昵称',
          align: "center",
          dataIndex: 'nickname'
        },
        {
          title: '申请等级',
          align: "center",
          dataIndex: 'levelName'
        },
        {
          title: '申请人姓名',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '手机号码',
          align: "center",
          dataIndex: 'phone'
        },
        {
          title: '微信号',
          align: "center",
          dataIndex: 'wechat'
        },
        {
          title: '性别',
          align: "center",
          dataIndex: 'sex',
          customRender: function (text) {
            return text == 1 ? '男' : text == 2 ? '女' : '未知'
          }
        },
        {
          title: '申请备注',
          align: "center",
          width: 300,
          dataIndex: 'remark'
        },
        {
          title: '创建时间',
          align: "center",
          width: 100,
          sorter: true,
          dataIndex: 'createTime'
        },
        {
          title: '申请状态',
          align: "center",
          dataIndex: 'status',
          scopedSlots: {customRender: 'statusSlot'}
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/mallPlus/hmsHandForm/list",
        delete: "/mallPlus/hmsHandForm/delete",
        deleteBatch: "/mallPlus/hmsHandForm/deleteBatch",
        exportXlsUrl: "/mallPlus/hmsHandForm/exportXls",
        importExcelUrl: "mallPlus/hmsHandForm/importExcel",

      },
      dictOptions: {},
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleEditRefuse(record) {
      let that = this
      record.status = 3
      putAction('/mallPlus/hmsHandForm/edit', record).then((res) => {
        if (res.success) {
          that.$message.success(res.message)

        } else {
          that.$message.warning(res.message)
        }
      })
    },
    handleEditPass(record) {
      let that = this
      record.status = 2
      putAction('/mallPlus/hmsHandForm/pass', record).then((res) => {
        if (res.success) {
          that.$message.success(res.message)

        } else {
          that.$message.warning(res.message)
        }
      })
    },
    initDictConfig() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
